package com.joycessh.action;

import java.sql.SQLException;

import com.joycessh.dao.UserDao;
import com.joycessh.dao.impl.UserDaoImpl;
import com.joycessh.vo.RegisterVO;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterAction extends ActionSupport {
	
	/**
	 * @author joycessh
	 */
	private static final long serialVersionUID = 1L;
	
	private RegisterVO user;
	private UserDao rDao;
	public RegisterVO getUser() {
		return user;
	}
	public void setUser(RegisterVO user) {
		this.user = user;
	}
	
	public String execute() {
		// TODO Auto-generated method stub
		try {
			rDao = new UserDaoImpl();
			if (rDao.isUsernameExist(user.getUsername())) {
				return "fail";
			} else {
				rDao.insertUser(user);
				return "success";
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return "input";
		}
		
	}
	

}
